<%--
    Document   : market
    Created on : Dec 12, 2009, 5:48:46 PM
    Author     : sclee
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.util.List" %>
<%@ page import="jhu.profiteer.data.Commodity" %>
<%@ page import="jhu.profiteer.data.CurrentCommodityValue" %>
<%@ page import="jhu.profiteer.data.AirplaneCargo" %>

<html>
  <%
    String pageTitle = "Market";
    String cssFile = "/profiteer-game/css/profiteer.css";
  %>
  <%@ include file="/WEB-INF/jspf/admin/header.jspf" %>
  <body>
    <%@ include file="/WEB-INF/jspf/title.jspf" %>
    <div class="contentArea Body">
      <div class="pagetitle">Market</div>
      <div class="pagebody">
        <table>
          <tr>
            <td id="menu"><%@ include file="/WEB-INF/jspf/menu.jspf" %></td>
            <td>
              <div class="divround">
                <h1>Welcome to Market!</h1>
                <%@ include file="/WEB-INF/jspf/admin/notice.jspf" %>
                <%
                  List<Commodity> clist = (List<Commodity>) session.getAttribute("clist");
                  List<CurrentCommodityValue> cvlist = (List<CurrentCommodityValue>) session.getAttribute("cvlist");
                  List<AirplaneCargo> aclist = (List<AirplaneCargo>) session.getAttribute("aclist");
                %>
                <form action="/profiteer-game/trade" method="post">
                  <table>
                    <tr>
                      <th id="left">Name</th>
                      <th id="left">Price</th>
                      <th id="left">Amount Owned</th>
                      <th id="left">Amount to Trade</th>
                    </tr>
                    <%
                      for (int i = 0; i < cvlist.size(); i++)
                      {
                        CurrentCommodityValue cv = (CurrentCommodityValue)cvlist.get(i);
                        AirplaneCargo ac = (AirplaneCargo) aclist.get(i);
                        Commodity c = (Commodity) clist.get(i);
                        session.setAttribute(c.getId().toString(),c.getName());
                    %>
                    <tr>
                      <td><a href="/profiteer-game/commodityInformation?commodityId=<%= c.getId() %>" name="commodityId"><%= c.getName() %></a></td>
                      <td><%= cv.getPrice() %></td>
                      <td><%= (ac == null) ? 0 : ac.getQuantity() %></td>
                      <td><input type="text" name="<%= cv.getId().getCommodityId() %>" /></td>
                    </tr>
                    <%
                      }
                    %>
                  </table>
                  <table>
                    <tr>
                      <td><input type="submit" name="submit" value="Buy" /></td>
                      <td><input type="submit" name="submit" value="Sell" /></td>
                    </tr>
                  </table>
                </form>
              </div>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <%@ include file="/WEB-INF/jspf/footer.jspf" %>
  </body>
</html>